package Project;
//___________________________IMPORTACIONES______________________________________

import java.awt.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.table.*;
import Validaciones.*;
import java.awt.event.*;
//______________________________________________________________________________

public class Usuario extends javax.swing.JDialog {
//_____________________________ATRIBUTOS________________________________________

    int Dialog;
    String sql;
    public boolean preciso = false;
//_____________________________CONSTRUCTOR______________________________________

    public Usuario(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        jLabel7.setText("");
        lblPrivilegio.setVisible(false);
        tblUsuarios.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lblUsuario.setVisible(false);
    }
//________________________________METODOS_______________________________________

    private void tamanoTablas() {

        int ancho = 500;
        int anchoColumna = 0;
        TableColumnModel modeloColumna = tblUsuarios.getColumnModel();
        TableColumn columnaTabla;
        for (int i = 0; i < tblUsuarios.getColumnCount(); i++) {
            columnaTabla = modeloColumna.getColumn(i);
            switch (i) {
                case 0:
                    anchoColumna = (23 * ancho) / 100;
                    break;
                case 1:
                    anchoColumna = (50 * ancho) / 100;
                    break;
                case 2:
                    anchoColumna = (23 * ancho) / 100;
                    break;
            }
            columnaTabla.setPreferredWidth(anchoColumna);
        }
    }
//______________________________________________________________________________

    public void llenarUsuarios() {

        BaseDeDatos.conectarse();

        try {

            sql = "SELECT usuarios.usuario, usuarios.contrasena, privilegios.privilegio, privilegios.id AS usuarios"
                    + " FROM usuarios JOIN privilegios ON (privilegios.id = usuarios.privilegio_id) ORDER BY privilegios.privilegio";

            DefaultTableModel modelo = new DefaultTableModel();
            tblUsuarios.setModel(modelo);
            modelo.addColumn("USUARIO");
            modelo.addColumn("<html>CONTRASEÑA<b>(MD5)</b></html>");
            modelo.addColumn("PRIVILEGIO");
            modelo.addColumn("PRIVILEGIO_ID");

            Statement s = BaseDeDatos.con.createStatement();
            ResultSet rs = s.executeQuery(sql);

            while (rs.next()) {
                // Se crea un array que será una de las filas de la tabla. 
                Object[] fila = new Object[4]; // Hay 4 columnas en la tabla

                // Se rellena cada posición del array con una de las columnas de la tabla en base de datos.
                for (int i = 0; i < 4; i++) {
                    fila[i] = rs.getObject(i + 1); // El primer indice en rs es el 1, no el cero, por eso se suma 1.
                }
                // Se añade al modelo la fila completa.
                modelo.addRow(fila);
            }
            BaseDeDatos.desconectarse();
            tblUsuarios.setModel(modelo);
            tamanoTablas();
            tblUsuarios.getColumnModel().getColumn(3).setMaxWidth(0);
            tblUsuarios.getColumnModel().getColumn(3).setMinWidth(0);
            tblUsuarios.getColumnModel().getColumn(3).setPreferredWidth(0);
            tblUsuarios.getColumnModel().getColumn(3).setResizable(false);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }

    }
//______________________________________________________________________________

    private void modificarUsuarios() {

        BaseDeDatos.conectarse();
        if (JOptionPane.showConfirmDialog(null, "Esta seguro de que desea modificar este registro",
                "Advertencia", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_NO_OPTION) {
            try {

                String d = txtNuevoUsuario.getText();
                String a = lblPrivilegio.getText();
                String c = "md5('" + txtNuevaContrasena.getText() + "')";

                sql = "update usuarios set usuario = '" + d.toLowerCase() + "', contrasena = " + c + ", privilegio_id = " + a + " where usuario = '" + d + "'";
                int resultado = BaseDeDatos.stmt.executeUpdate(sql);
                if (resultado == 1) {
                    JOptionPane.showMessageDialog(null, "El registro a sido modificado exitosamente", "Info", JOptionPane.INFORMATION_MESSAGE);
                    txtNuevaContrasena.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
                    txtNuevoUsuario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
                    txtRepetirNuevaContrasena.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
                }

            } catch (SQLException | HeadlessException e) {
                JOptionPane.showMessageDialog(null, "El registro no se pudo  modificar" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
        BaseDeDatos.desconectarse();
        llenarUsuarios();
    }
//______________________________________________________________________________

    private void insertarUsuarios() {

        BaseDeDatos.conectarse();

        if (JOptionPane.showConfirmDialog(null, "Esta seguro de ingresar este nuevo registro",
                "Advertencia", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_NO_OPTION) {
            try {

                String l, h, r;
                l = txtUsuario.getText();
                h = txtContrasena.getText();
                r = lblPrivilegio.getText();

                sql = "INSERT INTO usuarios VALUES('" + l.toLowerCase() + "', md5('" + h + "'), '" + r + "')";

                int resultado = BaseDeDatos.stmt.executeUpdate(sql);
                if (resultado == 1) {
                    JOptionPane.showMessageDialog(null, "El usuario se agrego de manera exitosa", "Info", JOptionPane.INFORMATION_MESSAGE);
                    txtContrasena.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
                    txtUsuario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
                    txtRepetirContrasena.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
                    txtUsuario.requestFocus();
                }
                BaseDeDatos.desconectarse();
                txtUsuario.setText("");
                txtContrasena.setText("");
                txtRepetirContrasena.setText("");
                rbtnUsuario.setSelected(true);
            } catch (HeadlessException | SQLException e) {
                JOptionPane.showMessageDialog(null, "Este usuario ya existe, por favor elija otro", "Error", JOptionPane.ERROR_MESSAGE);
                txtUsuario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));
                txtUsuario.requestFocus();
            }
        }
    }
//______________________________________________________________________________

    private void eliminarUsuario() {

        BaseDeDatos.conectarse();

        if (tblUsuarios.getSelectedRows().length < 1) {
            JOptionPane.showMessageDialog(null, "Seleccione Una Fila", "Error", JOptionPane.ERROR_MESSAGE);
        } else if (JOptionPane.showConfirmDialog(null, "Esta seguro de que desea eliminar este registro",
                "Advertencia", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_NO_OPTION) {
            try {
                lblUsuario.setText("" + tblUsuarios.getValueAt(tblUsuarios.getSelectedRow(), 0));
                String d = lblUsuario.getText();
                if (d.equals("superuser")) {
                    JOptionPane.showMessageDialog(null, "No se puede eliminar este usuario", "Error", JOptionPane.ERROR_MESSAGE);
                } else {

                    sql = "delete from usuarios where usuario= '" + d + "'";
                    int resultado = BaseDeDatos.stmt.executeUpdate(sql);
                    if (resultado == 1) {
                        JOptionPane.showMessageDialog(null, "El registro a sido eliminado", "Info", JOptionPane.INFORMATION_MESSAGE);
                    }
                }
            } catch (SQLException | HeadlessException e) {
                JOptionPane.showMessageDialog(null, "El registro no se pudo borrar Exepción:" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
        BaseDeDatos.desconectarse();
        llenarUsuarios();
    }
//______________________________________________________________________________

    private void cancelarModUsuarios() {

        txtNuevoUsuario.setEnabled(true);
        for (int i = 0; i < jPanel5.getComponents().length; i++) {
            jPanel5.getComponent(i).setEnabled(true);
        }
        btngNuevosPrivilegios.clearSelection();
        txtNuevoUsuario.setText("");
        txtNuevaContrasena.setText("");
        txtRepetirNuevaContrasena.setText("");
        dlgModificar.dispose();
    }
//______________________________________________________________________________

    private void cancelarUsuarios() {

        rbtnUsuario.setSelected(true);
        txtUsuario.setText("");
        txtContrasena.setText("");
        txtRepetirContrasena.setText("");
        this.dispose();

    }
//______________________________________________________________________________

    private void mayusActivado() {

        boolean value = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);

        if (value == true) {
            jLabel7.setText("Bloq Mayús Activado");
        } else if (value == false) {
            jLabel7.setText("");
        }

    }
//______________________________________________________________________________

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btngPrivilegios = new javax.swing.ButtonGroup();
        dlgTablaUsuarios = new javax.swing.JDialog();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblUsuarios = new javax.swing.JTable(){
            public boolean isCellEditable(int rowIndex, int colIndex) {
                return false; //Disallow the editing of any cell
            }
        };
        btnEliminar = new javax.swing.JButton();
        btnModificar = new javax.swing.JButton();
        lblUsuario = new javax.swing.JLabel();
        dlgModificar = new javax.swing.JDialog();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtNuevoUsuario = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        rbtnNuevoSuperUser = new javax.swing.JRadioButton();
        rbtnNuevoAdministrador = new javax.swing.JRadioButton();
        rbtnNuevoUsuario = new javax.swing.JRadioButton();
        btnAceptarUsuario = new javax.swing.JButton();
        txtNuevaContrasena = new javax.swing.JPasswordField();
        txtRepetirNuevaContrasena = new javax.swing.JPasswordField();
        btnCancelar = new javax.swing.JButton();
        btngNuevosPrivilegios = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtUsuario = new javax.swing.JTextField();
        btnIngresar = new javax.swing.JButton();
        txtContrasena = new javax.swing.JPasswordField();
        txtRepetirContrasena = new javax.swing.JPasswordField();
        jPanel3 = new javax.swing.JPanel();
        rbtnSuperUser = new javax.swing.JRadioButton();
        rbtnAdministrador = new javax.swing.JRadioButton();
        rbtnUsuario = new javax.swing.JRadioButton();
        lblPrivilegio = new javax.swing.JLabel();
        btnCancelarUsuario = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();

        dlgTablaUsuarios.setTitle("Usuarios");
        dlgTablaUsuarios.setMinimumSize(new java.awt.Dimension(523, 429));
        dlgTablaUsuarios.setModal(true);
        dlgTablaUsuarios.setResizable(false);

        tblUsuarios.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        tblUsuarios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tblUsuarios.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tblUsuarios.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(tblUsuarios);

        btnEliminar.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        btnEliminar.setText("Eliminar");
        btnEliminar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });

        btnModificar.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        btnModificar.setText("Modificar");
        btnModificar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarActionPerformed(evt);
            }
        });

        lblUsuario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 331, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lblUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout dlgTablaUsuariosLayout = new javax.swing.GroupLayout(dlgTablaUsuarios.getContentPane());
        dlgTablaUsuarios.getContentPane().setLayout(dlgTablaUsuariosLayout);
        dlgTablaUsuariosLayout.setHorizontalGroup(
            dlgTablaUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, dlgTablaUsuariosLayout.createSequentialGroup()
                .addContainerGap(11, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10))
        );
        dlgTablaUsuariosLayout.setVerticalGroup(
            dlgTablaUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dlgTablaUsuariosLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10))
        );

        dlgModificar.setTitle("Modificar Usuario");
        dlgModificar.setMinimumSize(new java.awt.Dimension(478, 203));
        dlgModificar.setModal(true);
        dlgModificar.setResizable(false);
        dlgModificar.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                dlgModificarWindowClosing(evt);
            }
        });

        jPanel4.setBorder(new javax.swing.border.MatteBorder(null));

        jLabel2.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel2.setText("Usuario:");

        jLabel5.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel5.setText("Contraseña:");

        jLabel6.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel6.setText("Repetir Contraseña:");

        txtNuevoUsuario.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        txtNuevoUsuario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        txtNuevoUsuario.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtNuevoUsuarioFocusGained(evt);
            }
        });

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Privilegios", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 12), new java.awt.Color(0, 0, 0))); // NOI18N
        jPanel5.setMaximumSize(new java.awt.Dimension(127, 106));
        jPanel5.setMinimumSize(new java.awt.Dimension(127, 106));

        btngNuevosPrivilegios.add(rbtnNuevoSuperUser);
        rbtnNuevoSuperUser.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        rbtnNuevoSuperUser.setText("Super Usuario");

        btngNuevosPrivilegios.add(rbtnNuevoAdministrador);
        rbtnNuevoAdministrador.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        rbtnNuevoAdministrador.setText("Administrador");

        btngNuevosPrivilegios.add(rbtnNuevoUsuario);
        rbtnNuevoUsuario.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        rbtnNuevoUsuario.setText("Usuario");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rbtnNuevoSuperUser)
                    .addComponent(rbtnNuevoAdministrador)
                    .addComponent(rbtnNuevoUsuario))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addComponent(rbtnNuevoSuperUser, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addComponent(rbtnNuevoAdministrador, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addComponent(rbtnNuevoUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5))
        );

        btnAceptarUsuario.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        btnAceptarUsuario.setText("Aceptar");
        btnAceptarUsuario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnAceptarUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarUsuarioActionPerformed(evt);
            }
        });

        txtNuevaContrasena.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        txtNuevaContrasena.setToolTipText("");
        txtNuevaContrasena.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        txtNuevaContrasena.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtNuevaContrasenaFocusGained(evt);
            }
        });
        txtNuevaContrasena.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNuevaContrasenaKeyPressed(evt);
            }
        });

        txtRepetirNuevaContrasena.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        txtRepetirNuevaContrasena.setToolTipText("");
        txtRepetirNuevaContrasena.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        txtRepetirNuevaContrasena.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtRepetirNuevaContrasenaFocusGained(evt);
            }
        });
        txtRepetirNuevaContrasena.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtRepetirNuevaContrasenaKeyReleased(evt);
            }
        });

        btnCancelar.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtNuevoUsuario)
                            .addComponent(txtNuevaContrasena, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtRepetirNuevaContrasena, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(btnAceptarUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNuevoUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(15, 15, 15)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNuevaContrasena, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(16, 16, 16)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtRepetirNuevaContrasena, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAceptarUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout dlgModificarLayout = new javax.swing.GroupLayout(dlgModificar.getContentPane());
        dlgModificar.getContentPane().setLayout(dlgModificarLayout);
        dlgModificarLayout.setHorizontalGroup(
            dlgModificarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dlgModificarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        dlgModificarLayout.setVerticalGroup(
            dlgModificarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dlgModificarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Nuevo Usuario");
        setMaximumSize(new java.awt.Dimension(498, 243));
        setMinimumSize(new java.awt.Dimension(498, 243));
        setModal(true);
        setPreferredSize(new java.awt.Dimension(498, 243));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Nuevo Usuario", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 14), new java.awt.Color(0, 0, 0))); // NOI18N
        jPanel1.setMaximumSize(new java.awt.Dimension(478, 194));
        jPanel1.setMinimumSize(new java.awt.Dimension(478, 194));

        jLabel1.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel1.setText("Usuario:");

        jLabel3.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel3.setText("Contraseña:");

        jLabel4.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel4.setText("Repetir Contraseña:");

        txtUsuario.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        txtUsuario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        txtUsuario.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtUsuarioFocusGained(evt);
            }
        });

        btnIngresar.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        btnIngresar.setText("Ingresar");
        btnIngresar.setBorder(null);
        btnIngresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIngresarActionPerformed(evt);
            }
        });

        txtContrasena.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        txtContrasena.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        txtContrasena.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtContrasenaFocusGained(evt);
            }
        });
        txtContrasena.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtContrasenaKeyPressed(evt);
            }
        });

        txtRepetirContrasena.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        txtRepetirContrasena.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        txtRepetirContrasena.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtRepetirContrasenaFocusGained(evt);
            }
        });
        txtRepetirContrasena.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtRepetirContrasenaKeyReleased(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Privilegios", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 12), new java.awt.Color(0, 0, 0))); // NOI18N
        jPanel3.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jPanel3.setMaximumSize(new java.awt.Dimension(137, 108));
        jPanel3.setMinimumSize(new java.awt.Dimension(137, 108));

        btngPrivilegios.add(rbtnSuperUser);
        rbtnSuperUser.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        rbtnSuperUser.setText("Super User");

        btngPrivilegios.add(rbtnAdministrador);
        rbtnAdministrador.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        rbtnAdministrador.setText("Administrador");

        btngPrivilegios.add(rbtnUsuario);
        rbtnUsuario.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        rbtnUsuario.setSelected(true);
        rbtnUsuario.setText("Usuario");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rbtnSuperUser, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rbtnAdministrador, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rbtnUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addComponent(rbtnSuperUser, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addComponent(rbtnAdministrador, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addComponent(rbtnUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        lblPrivilegio.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        lblPrivilegio.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblPrivilegio.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        btnCancelarUsuario.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        btnCancelarUsuario.setText("Cancelar");
        btnCancelarUsuario.setBorder(null);
        btnCancelarUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarUsuarioActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(255, 0, 0));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtContrasena, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtUsuario, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtRepetirContrasena, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnIngresar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblPrivilegio, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(25, 25, 25)
                        .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(8, 8, 8)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelarUsuario, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(15, 15, 15)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtContrasena, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(16, 16, 16)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtRepetirContrasena, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 106, Short.MAX_VALUE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblPrivilegio)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(btnIngresar, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btnCancelarUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addGap(10, 10, 10))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(39, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
//______________________________________________________________________________

    private void btnIngresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIngresarActionPerformed

        if (rbtnSuperUser.isSelected()) {
            lblPrivilegio.setText("1");
        } else if (rbtnAdministrador.isSelected()) {
            lblPrivilegio.setText("2");
        } else if (rbtnUsuario.isSelected()) {
            lblPrivilegio.setText("3");
        }

        String nom = txtUsuario.getText();
        String pass1 = txtContrasena.getText();
        String pass2 = txtRepetirContrasena.getText();


        if (ValidacionesUsuarios.validaUsuarios(nom, txtUsuario) || ValidacionesUsuarios.validaContrasena(pass1, txtContrasena) || ValidacionesUsuarios.validaContrasena(pass2, txtRepetirContrasena)) {
            JOptionPane.showMessageDialog(jPanel1, "Por favor verifique los datos", "Error", JOptionPane.ERROR_MESSAGE);
        } else if (preciso == false) {
            JOptionPane.showMessageDialog(jPanel1, "Por favor verifique la coincidencia de contraseñas", "Error", JOptionPane.ERROR_MESSAGE);
            txtRepetirContrasena.requestFocus();
            txtRepetirContrasena.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));
        } else {
            insertarUsuarios();
        }

    }//GEN-LAST:event_btnIngresarActionPerformed
//______________________________________________________________________________

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed

        eliminarUsuario();

    }//GEN-LAST:event_btnEliminarActionPerformed
//______________________________________________________________________________

    private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarActionPerformed

        if (tblUsuarios.getSelectedRows().length < 1) {
            JOptionPane.showMessageDialog(null, "Seleccione Una Fila", "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            txtNuevoUsuario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
            txtNuevaContrasena.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
            txtRepetirNuevaContrasena.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
            txtNuevoUsuario.setText("" + tblUsuarios.getValueAt(tblUsuarios.getSelectedRow(), 0));
            lblPrivilegio.setText("" + tblUsuarios.getValueAt(tblUsuarios.getSelectedRow(), 3));

            if (txtNuevoUsuario.getText().equals("superuser")) {
                txtNuevoUsuario.setEnabled(false);
                for (int i = 0; i < jPanel5.getComponents().length; i++) {
                    jPanel5.getComponent(i).setEnabled(false);
                }
            }

            switch (lblPrivilegio.getText()) {
                case "1":
                    rbtnNuevoSuperUser.setSelected(true);
                    break;
                case "2":
                    rbtnNuevoAdministrador.setSelected(true);
                    break;
                case "3":
                    rbtnNuevoUsuario.setSelected(true);
                    break;
            }
            dlgModificar.setLocationRelativeTo(this);
            dlgModificar.setVisible(true);
        }

    }//GEN-LAST:event_btnModificarActionPerformed
//______________________________________________________________________________

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed

        cancelarModUsuarios();

    }//GEN-LAST:event_btnCancelarActionPerformed
//______________________________________________________________________________

    private void btnAceptarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarUsuarioActionPerformed

        String nom = txtNuevoUsuario.getText();
        String pass1 = txtNuevaContrasena.getText();
        String pass2 = txtRepetirNuevaContrasena.getText();

        if (ValidacionesUsuarios.validaUsuarios(nom, txtNuevoUsuario) || ValidacionesUsuarios.validaContrasena(pass1, txtNuevaContrasena) || ValidacionesUsuarios.validaContrasena(pass2, txtRepetirNuevaContrasena)) {
            JOptionPane.showMessageDialog(jPanel4, "Por favor verifique los datos", "Error", JOptionPane.ERROR_MESSAGE);
        } else if (preciso == false) {
            JOptionPane.showMessageDialog(jPanel4, "Por favor verifique la coincidencia de contraseñas", "Error", JOptionPane.ERROR_MESSAGE);
            txtRepetirNuevaContrasena.requestFocus();
            txtRepetirNuevaContrasena.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));
        } else {
            modificarUsuarios();
            txtNuevoUsuario.setEnabled(true);
            for (int i = 0; i < jPanel5.getComponents().length; i++) {
                jPanel5.getComponent(i).setEnabled(true);
            }
            btngNuevosPrivilegios.clearSelection();
            txtNuevoUsuario.setText("");
            txtNuevaContrasena.setText("");
            txtRepetirNuevaContrasena.setText("");
            dlgModificar.dispose();
        }

    }//GEN-LAST:event_btnAceptarUsuarioActionPerformed
//______________________________________________________________________________

    private void dlgModificarWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_dlgModificarWindowClosing

        cancelarModUsuarios();

    }//GEN-LAST:event_dlgModificarWindowClosing
//______________________________________________________________________________

    private void txtRepetirContrasenaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRepetirContrasenaKeyReleased

        mayusActivado();

        String pass1 = txtContrasena.getText();
        String pass2 = txtRepetirContrasena.getText();
        if (pass2.equals(pass1)) {
            preciso = true;
        } else if (!pass2.equals(pass1)) {
            preciso = false;
        }

    }//GEN-LAST:event_txtRepetirContrasenaKeyReleased
//______________________________________________________________________________

    private void txtRepetirNuevaContrasenaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRepetirNuevaContrasenaKeyReleased

        mayusActivado();

        String pass1 = txtNuevaContrasena.getText();
        String pass2 = txtRepetirNuevaContrasena.getText();
        if (pass2.equals(pass1)) {
            preciso = true;
        } else if (!pass2.equals(pass1)) {
            preciso = false;
        }

    }//GEN-LAST:event_txtRepetirNuevaContrasenaKeyReleased
//______________________________________________________________________________

    private void btnCancelarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarUsuarioActionPerformed

        cancelarUsuarios();

    }//GEN-LAST:event_btnCancelarUsuarioActionPerformed
//______________________________________________________________________________

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing

        cancelarUsuarios();

    }//GEN-LAST:event_formWindowClosing
//______________________________________________________________________________

    private void txtContrasenaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtContrasenaKeyPressed

        mayusActivado();

    }//GEN-LAST:event_txtContrasenaKeyPressed
//______________________________________________________________________________

    private void txtContrasenaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtContrasenaFocusGained

        mayusActivado();

    }//GEN-LAST:event_txtContrasenaFocusGained
//______________________________________________________________________________

    private void txtRepetirContrasenaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtRepetirContrasenaFocusGained

        mayusActivado();

    }//GEN-LAST:event_txtRepetirContrasenaFocusGained
//______________________________________________________________________________

    private void txtUsuarioFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtUsuarioFocusGained

        jLabel7.setText("");

    }//GEN-LAST:event_txtUsuarioFocusGained
//______________________________________________________________________________

    private void txtNuevaContrasenaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtNuevaContrasenaFocusGained

        mayusActivado();

    }//GEN-LAST:event_txtNuevaContrasenaFocusGained
//______________________________________________________________________________

    private void txtNuevaContrasenaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNuevaContrasenaKeyPressed

        mayusActivado();

    }//GEN-LAST:event_txtNuevaContrasenaKeyPressed
//______________________________________________________________________________

    private void txtRepetirNuevaContrasenaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtRepetirNuevaContrasenaFocusGained

        mayusActivado();

    }//GEN-LAST:event_txtRepetirNuevaContrasenaFocusGained
//______________________________________________________________________________

    private void txtNuevoUsuarioFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtNuevoUsuarioFocusGained

        jLabel7.setText("");

    }//GEN-LAST:event_txtNuevoUsuarioFocusGained
//______________________________________________________________________________
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptarUsuario;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnCancelarUsuario;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnIngresar;
    private javax.swing.JButton btnModificar;
    private javax.swing.ButtonGroup btngNuevosPrivilegios;
    private javax.swing.ButtonGroup btngPrivilegios;
    private javax.swing.JDialog dlgModificar;
    public static javax.swing.JDialog dlgTablaUsuarios;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblPrivilegio;
    private javax.swing.JLabel lblUsuario;
    private javax.swing.JRadioButton rbtnAdministrador;
    private javax.swing.JRadioButton rbtnNuevoAdministrador;
    private javax.swing.JRadioButton rbtnNuevoSuperUser;
    private javax.swing.JRadioButton rbtnNuevoUsuario;
    private javax.swing.JRadioButton rbtnSuperUser;
    private javax.swing.JRadioButton rbtnUsuario;
    private javax.swing.JTable tblUsuarios;
    private javax.swing.JPasswordField txtContrasena;
    private javax.swing.JPasswordField txtNuevaContrasena;
    private javax.swing.JTextField txtNuevoUsuario;
    private javax.swing.JPasswordField txtRepetirContrasena;
    private javax.swing.JPasswordField txtRepetirNuevaContrasena;
    private javax.swing.JTextField txtUsuario;
    // End of variables declaration//GEN-END:variables
}
